<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Mod_reviews extends CI_Controller {
	private $per_page = 2;
	private $total_rows = 12;
	private $uri_page = '';
	private $base_page = '';
	private $uri_segment = '';
	function __construct() {
		parent::__construct();
	}
	function index() {
		$offset               = preg_replace("/(.html)/", '', $this->security->xss_clean($this->uri->segment(1, 0)));
		$this->base_page      = $this->uri->segment(1) . '/';
		$this->uri_segment    = 1;
		$reviews_students     = $this->common_model->getdata('reviews', array(
			'publish' => 1,
			'type' => 0
		), '', array(
			'id',
			'ASC'
		));
		$num_reviews_students = $this->common_model->getnumber2('reviews', array(
			'publish' => 1,
			'type' => 1
		));
		$this->total_rows     = $num_reviews_students;
		$this->phantrang();
		$data['title']   = 'Ý kiến người dùng';
		$data['content'] = $this->load->view('mod_reviews/views_reviews', array(
			'reviews_students' => $reviews_students
		), true);
		$this->load->view('index', $data);
	}
	function write_reviews() {
		$title    = $this->input->post('tittle_reviews');
		$content  = $this->input->post('rv_content');
		$userid   = $this->session->userdata('id');
		$thongbao = '';
		$acc      = $this->common_model->getone('users', array(
			'id' => $this->session->userdata('id')
		));
		// FORM VALIDATE
		$this->load->library('form_validation');
		$this->form_validation->set_rules('tittle_reviews', 'Tiêu đề', 'required');
		$this->form_validation->set_rules('rv_content', 'Nội dung', 'required');
		if ($this->form_validation->run() == FALSE) {
			
		} else {
			$this->common_model->insertdata('reviews', array(
				'userid' => $userid,
				'title' => $title,
				'content' => $content,
				'type' => $acc->type
			));
			$thongbao = '<h3 style="color:green;">Cảm ơn bạn đã gửi ý kiến cho 10 cộng !! Sự đóng góp của bạn là niềm vinh hạnh cho chúng tôi!</h3>';
		}
		$data['content'] = $this->load->view('mod_reviews/views_write_reviews.php', array(
			'thongbao' => $thongbao
		), true);
		$this->load->view('index', $data);
	}
	function reviews_giasu() {
		$offset               = preg_replace("/(.html)/", '', $this->security->xss_clean($this->uri->segment(1, 0)));
		$this->base_page      = $this->uri->segment(1) . '/';
		$this->uri_segment    = 1;
		$reviews_students     = $this->common_model->getdata('reviews', array(
			'publish' => 1,
			'type' => 1
		), '', array(
			'id',
			'ASC'
		));
		$num_reviews_students = $this->common_model->getnumber2('reviews', array(
			'publish' => 1,
			'type' => 1
		));
		$this->total_rows     = $num_reviews_students;
		$this->phantrang();
		$data['title']   = 'Ý kiến người dùng';
		$data['content'] = $this->load->view('mod_reviews/views_reviews_giasu.php', array(
			'reviews_students' => $reviews_students
		), true);
		$this->load->view('index', $data);
	}
	function reviews_st_tutor() {
		$offset            = preg_replace("/(.html)/", '', $this->security->xss_clean($this->uri->segment(1, 0)));
		$this->base_page   = $this->uri->segment(1) . '/';
		$this->uri_segment = 1;
		$st_tt             = $this->common_model->getdata('rating_des');
		$tutal_row         = $this->common_model->getdata('rating_des', '', '', '', array(
			$this->per_page,
			$offset
		));
		$this->total_rows  = $tutal_row;
		$data['content']   = $this->load->view('mod_reviews/views_reviews_st_tt.php', array(
			'reviews' => $st_tt
		), true);
		$data['title']     = 'Học sinh ý kiến gia sư';
		$this->load->view('index', $data);
	}
	function phantrang() {
		$this->load->library('pagination');
		$config['base_url']    = base_url() . $this->uri->segment(1) . '/';
		$config['total_rows']  = $this->total_rows;
		$config['per_page']    = $this->per_page;
		$config['uri_segment'] = 2;
		$config['num_links']   = 12;
		$this->pagination->initialize($config);
	}
}
?>